const express = require("express");
const articleCtrl = require("../controller/article");
const auth = require("../middleware/auth");
const router = express.Router();
const articleValidator = require("../validator/article");

// 获取文章列表
router.get("/", articleCtrl.getAriticles);

// 获取用户关注的作者文章列表
router.get("/feed", articleCtrl.getFeedArticles);

// 获取文章
router.get(
  "/:articleId",
  auth,
  articleValidator.getArticle,
  articleCtrl.getAriticle
);

// 创建文章
router.post(
  "/",
  auth,
  articleValidator.createArticle,
  articleCtrl.createAriticle
);

// 更新文章
router.put(
  "/:articleId",
  auth,
  articleValidator.updateArticle,
  articleCtrl.updateArticle
);

// 删除文章
router.delete(
  "/:articleId",
  auth,
  articleValidator.deleteAriticle,
  articleCtrl.deleteAriticle
);

// 添加文章评论
router.post("/:articleId/comments", articleCtrl.addComments);

// 获取文章评论
router.get("/:articleId/comments", articleCtrl.getComments);

// 删除文章评论
router.delete("/:articleId/comments/:id", articleCtrl.deleteComments);

// 标记喜欢的文章
router.post("/:articleId/favorite", articleCtrl.favoriteArticles);

// 标记不喜欢的文章
router.delete("/:articleId/favorite", articleCtrl.unfavoriteArticles);

module.exports = router;
